package com.cscec5b.inspection.service;

import com.cscec5b.inspection.entity.RmcRecord;
import com.cscec5b.inspection.repository.RmcRecordRepository;
//import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
//@RequiredArgsConstructor
public class RmcRecordAppService {
    private final RmcRecordRepository repo;

    public RmcRecordAppService(RmcRecordRepository repo) {
        this.repo = repo;
    }

    public Map<String,Object> save(RmcRecord d){
        RmcRecord saved = repo.save(d);
        return Map.of("ok", true, "id", saved.getId());
    }

    public Map<String,Object> detail(long id){
        return Map.of("data", repo.findById(id).orElse(null));
    }

    public List<RmcRecord> listByProject(long projectId){
        return repo.findByProjectIdOrderByIdDesc(projectId);
    }
}
